package com.seashell.demo.swaggerspringboot.controller;

import com.seashell.demo.swaggerspringboot.domain.Test;
import com.seashell.demo.swaggerspringboot.result.RequestResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("demo")
@Api(value="Demo服务",description = "demo服务描述",tags={"Demo服务"})
public class DemoController {

    @ApiOperation(value = "demo服务的get方法")
    @RequestMapping(value = "{id}",method = RequestMethod.GET)
    public Test get(@ApiParam(value = "id参数描述", required = true) @PathVariable Integer id){
        Test model = new Test();
        model.setId(id);
        model.setContent("content");
        String[] array = new String[]{"array1","array2","array3"};
        model.setArray(array);

        List<String> list = new ArrayList<>();
        list.add("list item 1");
        list.add("list item 2");
        list.add("list item 3");
        list.add("list item 4");
        model.setList(list);
        return model;
    }

    @ApiOperation(value = "demo服务的post方法")
    @RequestMapping(method = RequestMethod.POST)
    public Test post(Test model){
        return model;
    }

    @ApiOperation(value = "demo服务的put方法")
    @RequestMapping(method = RequestMethod.PUT)
    public RequestResult put(Test model){
        RequestResult result = new RequestResult();
        result.setIsSuccess(0);
        result.setDescription("执行成功");
        return result;
    }
}
